﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Prototype.FeedTheWorld
{
    public class PlayerController : MonoBehaviour
    {
        [Header("Move Config")]
        public float horizontalInput;
        public float speed = 10f;
        public float rangeX = 10f;
        [Header("Projectile")]
        public GameObject projectilePrefab;

        // Update is called once per frame
        void Update()
        {
            var mPosition = transform.position;
            if(transform.position.x < -rangeX)
            {
                
                mPosition = new Vector3(-rangeX,mPosition.y,mPosition.z);
                transform.position = mPosition;
            }
            else if (transform.position.x > rangeX)
            {
                 mPosition = new Vector3(rangeX,mPosition.y,mPosition.z);
                transform.position = mPosition;
            }
            
            horizontalInput = Input.GetAxis("Horizontal");
            transform.Translate(speed * horizontalInput * Time.deltaTime * Vector3.right );

            if (Input.GetKeyDown(KeyCode.Space))
            {
                Instantiate(projectilePrefab,transform.position,projectilePrefab.transform.rotation);
            }
        }
    }
}